<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

/**
 * 市场
 */
class Bazaar extends Frontend
{
    protected $layout = '';
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    public function index() {
        $userId = $this->auth->id;
        if($this->request->isPost()){
            $page = $this->request->param('page',1);
            $type = $this->request->param('type',0); //0 全部状态
            $list = Db::name('user_weighting_score_detail')->where(['user_id'=>$userId])->where(['status'=>1]);
            if(!empty($type)){
                $list->where(['type'=>$type]);
            }
            $list = $list->page($page,10)->order('id DESC')->select();
            
            foreach ($list as &$value) {
                $value['add_time'] = date('Y/m/d H:i',$value['add_time']);
            }
            $this->success($userId,'',$list);
        }
        $user = Db::name('user')->where(['id'=>$userId])->find();
        $completeInfo = Db::name('user_weighting_task')->where(['user_id'=>$userId,'month'=>date('Ym')])->order('id DESC')->find();
        $this->assign("user", $user);
        $this->assign("completeInfo", $completeInfo);
        $this->assign("isFinish", (empty($completeInfo)||$completeInfo['status']==0)?FALSE:TRUE);
        
        return $this->view->fetch();
    }
    public function district() {
        $userId = $this->auth->id;
        if($this->request->isPost()){
            $page = $this->request->param('page',1);
            $type = $this->request->param('type',0); //0 全部状态
            $list = Db::name('user_weighting_score_detail')->where(['user_id'=>$userId]);
            if(!empty($type)){
                $list->where(['type'=>$type]);
            }
            $list = $list->page($page,10)->order('id DESC')->select();
            
            foreach ($list as &$value) {
                $value['add_time'] = date('Y/m/d H:i',$value['add_time']);
            }
            $this->success($userId,'',$list);
        }
        $user = Db::name('user')->where(['id'=>$userId])->find();
        $completeInfo = Db::name('user_weighting_task')->where(['user_id'=>$userId,'month'=>date('Ym')])->order('id DESC')->find();
        $this->assign("user", $user);
        $this->assign("completeInfo", $completeInfo);
        $this->assign("isFinish", (empty($completeInfo)||$completeInfo['status']==0)?FALSE:TRUE);
        
        return $this->view->fetch();
    }

}
